package com.shsxt.crm.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shsxt.crm.dao.YgReportDao;
import com.shsxt.crm.model.YgCustomerServer;
import com.shsxt.crm.model.YgReport;
import com.shsxt.crm.service.IReportService;

/**
 * 
 * 报表管理
 * 
 * @author Mr.YongGan.Zhang
 *
 */
@Service
public class ReportServiceImpl implements IReportService {

	@Autowired
	private YgReportDao ygReportDao;

	@Override
	public Map<String, Object> queryCustomersContribution(String name, Integer pageNum, Integer rows) {

		PageHelper.startPage(pageNum, rows);

		List<YgReport> contribution = ygReportDao.queryCustomersContribution(name);

		PageInfo<YgReport> info = new PageInfo<>(contribution);

		Map<String, Object> map = new HashMap<>();

		map.put("total", info.getTotal());
		map.put("rows", info.getList());
		return map;
	}

	@Override
	public Map<String, Object> queryCustomersGc() {

		List<YgReport> customersGc = ygReportDao.queryCustomersGc();
		// 客户等级
		List<String> level = new ArrayList<>();
		// 客户数量
		List<Integer> count = new ArrayList<>();

		for (YgReport ygReport : customersGc) {
			level.add(ygReport.getLevel());
			count.add(ygReport.getCount());
		}
		Map<String, Object> map = new HashMap<>();

		map.put("code", 200);
		map.put("level", level);
		map.put("count", count);
		return map;
	}

	@Override
	public Map<String, Object> queryCustomersServerAnalysis() {

		List<YgCustomerServer> analysis = ygReportDao.queryCustomersServerAnalysis();

		List<String> Legend = new ArrayList<>();

		for (YgCustomerServer temp : analysis) {
			Legend.add(temp.getName());// 存放图例
		}
		Map<String, Object> map = new HashMap<>();

		map.put("code", 200);
		map.put("Legend", Legend);
		map.put("customerServer", analysis);
		return map;
	}
}
